import React, { Component } from 'react';
import { connect } from 'dva';
import { message, Modal, Pagination, Popconfirm, Button, Form, DatePicker, Card, Table } from 'antd';
import styles from './../Users.css';
import moment from 'moment';
import Factory from '../../factory';
import dataEditCreate from '../../addons/DataEdit'
import * as datetime from '../../../utils/datetime'
import * as compDiviService from '../../../services/AccountDivi';
const ButtonGroup = Button.Group;
class BaseFYSJForm extends Component {
  constructor(props) {
    super(props);
    this.state = {
      dateValue: null,
      loading:false
    }
  }
  showDiviHandler() {
    let dateString = this.state.dateValue;
    let ods = this.props.odsDate
    if (dateString && dateString > ods) {
      message.error("日期不能大于系统当前日期")
      return
    } else {
      this.setState({loading:true})  
      compDiviService.CreateData({ dateString}
      ).then(function (data) {
        if (data === 'OK') {
          message.success('数据生成成功！')
          this.setState({loading:false})  
        } else {
          message.error('数据生成失败！' + data)
          return;
        }
      }.bind(this)).catch(function (ex) {
        console.log('请求出错', ex)
      });
    }
  }
  SelDate(date, dateString) {
    this.state.dateValue = dateString;
  }
  render() {
    let { showEdit, record, offsetWidth, offsetHeight, permID, popedomTypes } = this.props
    let x = (offsetWidth / 2 - 10) / 2
    let y = offsetHeight - 115
    return (
      <div className={styles.normal} style={{ background: '#fff', marginTop: -16, padding: '5px 5px' }}>
        <Card style={{ height: y }} bodyStyle={{ padding: 0 }}>
          <div style={{ marginLeft: x, align: 'center', color: 'red' }}>
            <br /><br /><br /><br />
            注意：<br />
            此功能在只适用于业务分析向下的数据生成;<br />
            <br />
            <div style={{ align: 'center' }}>
              <span style={{ color: 'black', height: 50 }}>
                日期: &nbsp;&nbsp;&nbsp;&nbsp;
              </span>
              <span>
                <DatePicker onChange={this.SelDate.bind(this)} style={{ 'vertical-align': 'bottom' }} />
              </span>
              <span style={{ marginLeft: 40 }}><Button loading={this.state.loading} onClick={this.showDiviHandler.bind(this)} type="primary">生成费用数据</Button>
              </span>
            </div>
          </div>
        </Card>
      </div>
    )
  }
}

function mapStateToProps(state) {
  const { offsetHeight, userID, orgID, pOrgID, popedomTypes, offsetWidth, odsDate } = state.menus
  return {
    userID,
    orgID,
    pOrgID,
    popedomTypes,
    offsetHeight,
    offsetWidth,
    odsDate
  }
}
BaseFYSJForm = connect(mapStateToProps)(BaseFYSJForm)
export default BaseFYSJForm;

let render = (props) => React.createElement(BaseFYSJForm, props);
let f = new Factory()
f.set("BaseFYSJForm", render)
